package com.order.utils;

import com.order.hit.crossover.platform.common.bean.order.OrderState;
import com.order.hit.crossover.platform.common.dao.OrderDao;
import com.order.hit.crossover.platform.common.utils.TimeChange;
import com.order.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author Lei
 * @version 0.1
 * @date 2020/8/19
 */
@Component
public class OverTimeJudge {

    @Autowired
    private OrderMapper orderMapper;
    /**
     * 判断订单是否超时
     */
    public void judgeOrderIfOverTime(){
        List<OrderDao> list = this.orderMapper.getAllorder();
        for(OrderDao orderDao : list){
            String end_time = orderDao.getEnd_time();
            String nowTime = new SimpleDateFormat("yyyy.MM.dd.HH").format(new Date());
            if (TimeChange.getDate(end_time).before(TimeChange.getDate(nowTime)) && orderDao.getOrderState().equalsIgnoreCase(OrderState.ORDER_DISPLAY.toString())){
                //表示为 订单超时
                orderDao.setOrderState(OrderState.ORDER_OVERTIME.toString());
                this.orderMapper.updateOrder(orderDao);
            }
        }
    }

}
